﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using MbUnit.Framework;

namespace Mite.Core.Tests.Domain
{
	[TestFixture]
	public class ForeignKeyTestFixture
	{
		[Test]
		public void Constructor_assumes_foreign_key_to_reference_table_primary_key()
		{
			var refPrimaryKey = new Column("Id", DbType.Int32, ColumnAttributes.PrimaryKey);

			Table table = new Table("table", new Column("Id", DbType.Int32, ColumnAttributes.PrimaryKey));
			Table refTable = new Table("refTable", refPrimaryKey);
			var fk = new ForeignKey(table, refTable);

			Assert.AreEqual(1, fk.ReferenceMap.Count());
		}

		[Test]
		public void Columns_added_to_table_follow_convention_based_name()
		{
			var refPrimaryKey = new Column("Id", DbType.Int32, ColumnAttributes.PrimaryKey);

			Table table = new Table("table", new Column("Id", DbType.Int32, ColumnAttributes.PrimaryKey));
			Table refTable = new Table("refTable", refPrimaryKey);
			var fk = new ForeignKey(table, refTable);

			Assert.AreEqual("refTableId", fk.ReferenceMap.Single().Key.Name);
		}
	}
}
